<script>
import api from '@/api'

export default {
  name: 'joinList',
  data() {
    return {
      id: 0,
      isLoading: false,
      joinList: [],
      total_num: 0,
      winner_total_num: 0,
      page: 1,
      last_page: 1,
    }
  },
  onLoad(options) {
    this.id = options.id
    this.getJoinList()
  },
  methods: {
    async getJoinList() {
      await uni.showLoading()
      try {
        const result = await api.welfareHouses.joinList({
          weal_room_id: this.id,
          /*user_id: 13145,*/
          page: this.page
        })

        if (result.code !== 200) throw new Error('数据获取失败')
        if (this.page === 1) {
          this.joinList = result.data.data
        } else {
          this.joinList.push(...result.data.data)
        }
        this.page ++
        this.last_page = result.data.last_page
        this.total_num = result.data.total_num
        this.winner_total_num = result.data.winner_total_num
      } catch (e) {
        await uni.showToast({ icon: 'none', title: e.message })
      } finally {
        this.isLoading = false
        await uni.hideLoading()
      }
    },
    onRefresh() {
      this.page = 1
      this.isLoading = true
      this.getJoinList()
    },
    onLoadMore() {
      if (this.page >= this.last_page) return
      // 加载更多
      this.getJoinList()
    }
  },
}
</script>

<template>
  <view class="join-list-layout">
    <my-header title="参与人员" background-color="transparent"></my-header>
    <my-content style="height: 100%;">
      <scroll-view scroll-y="true" style="overflow-y: hidden; height: 100%;" refresher-background="" :refresher-enabled="true"
                   @refresherrefresh="onRefresh" :refresher-triggered="isLoading" @scrolltolower="onLoadMore">
        <my-join-list :total="total_num" :num="winner_total_num" :data="joinList"></my-join-list>
      </scroll-view>
    </my-content>
  </view>
</template>

<style scoped lang="scss">
.join-list-layout {
  height: 100vh;
  width: 100%;
  background-image: url("https://www.dingxians.cn/upload/images/common/bg.png");
  background-size: 100% 100%;
}
</style>